import { requestClient } from '#/api/request';

export namespace TaskServiceTypeApi {
  export interface TaskServiceTypeRecord {
    id: number;
    name: string;
    created_at: string;
    updated_at: string;
  }

  export interface ListParams {
    page?: number;
    per_page?: number;
    keyword?: string;
  }

  export interface ListResponse {
    items: TaskServiceTypeRecord[];
    pagination: {
      total: number;
      per_page: number;
      current_page: number;
      last_page: number;
    };
  }

  export interface UpsertPayload {
    name: string;
  }
}

export async function getTaskServiceTypesApi(params?: TaskServiceTypeApi.ListParams) {
  return requestClient.get<TaskServiceTypeApi.ListResponse>('/api/admin/task-service-types', {
    params,
  });
}

export async function createTaskServiceTypeApi(payload: TaskServiceTypeApi.UpsertPayload) {
  return requestClient.post<TaskServiceTypeApi.TaskServiceTypeRecord>(
    '/api/admin/task-service-types',
    payload,
  );
}

export async function updateTaskServiceTypeApi(
  id: number,
  payload: TaskServiceTypeApi.UpsertPayload,
) {
  return requestClient.put<TaskServiceTypeApi.TaskServiceTypeRecord>(
    `/api/admin/task-service-types/${id}`,
    payload,
  );
}

export async function deleteTaskServiceTypeApi(id: number) {
  return requestClient.delete<void>(`/api/admin/task-service-types/${id}`);
}
